package com.vehicle.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.vehicle.bean.DataGridView;
import com.vehicle.mapper.RemindMapper;
import com.vehicle.pojo.Remind;
import com.vehicle.service.RemindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RemindServiceImpl implements RemindService {
    @Autowired
    private RemindMapper remindMapper;
    @Transactional(
            propagation = Propagation.NOT_SUPPORTED
    )
    @Override
    public DataGridView findAll(Remind remind) {
        Page<Object> page = PageHelper.startPage(remind.getPage(),remind.getLimit() );
        List<Remind> reminds = remindMapper.selectAll(remind);
        DataGridView dataGridView=new DataGridView();
        dataGridView.setCount(page.getTotal());
        dataGridView.setData(reminds);
        return dataGridView;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public DataGridView findAllRemind() {
        DataGridView dataGridView = new DataGridView();
        dataGridView.setData(remindMapper.selectAllRemind());
        return dataGridView;
    }
}
